file chooser: Use batched insertion for search results
authorMatthias Clasen <mclasen@redhat.com>
Thu, 18 Jun 2015 16:20:21 +0000 (12:20 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 18 Jun 2015 17:11:30 +0000 (13:11 -0400)
This helps avoiding excess work when procesing many search
results, as typically happens with short search strings
and recursive search.

https://bugzilla.gnome.org/show_bug.cgi?id=751169

gtk/gtkfilechooserwidget.c

index 259b6f58bee9aa6344b066c74976d487a9e8abfc..2bba90235aaa2a13a712815b88c900f230bc4be7 100644 (file)
@@ -6119,40 +6119,31 @@ search_get_selected_files (GtkFileChooserWidget *impl)
   return result;
 }
 
-/* Adds one hit from the search engine to the search_model */
+/* Callback used from GtkSearchEngine when we get new hits */
 static void
-search_add_hit (GtkFileChooserWidget *impl,
-               gchar                 *uri)
+search_engine_hits_added_cb (GtkSearchEngine      *engine,
+                            GList                *hits,
+                            GtkFileChooserWidget *impl)
 {
-  GtkFileChooserWidgetPrivate *priv = impl->priv;
+  GList *l, *files;
   GFile *file;
+  const char *uri;
 
-  file = g_file_new_for_uri (uri);
-  if (!file)
-    return;
-
-  priv->search_model_empty = FALSE;
-
-  _gtk_file_system_model_add_and_query_file (priv->search_model,
-                                             file,
-                                             MODEL_ATTRIBUTES);
-
-  g_object_unref (file);
-}
-
-/* Callback used from GtkSearchEngine when we get new hits */
-static void
-search_engine_hits_added_cb (GtkSearchEngine *engine,
-                            GList           *hits,
-                            gpointer         data)
-{
-  GtkFileChooserWidget *impl;
-  GList *l;
+  files = NULL;
+  for (l = hits; l; l = l->next)
+    {
+      uri = (const gchar *)l->data;
+      file = g_file_new_for_uri (uri);
+      if (!file)
+        continue;
+      files = g_list_prepend (files, file);
+    }
 
-  impl = GTK_FILE_CHOOSER_WIDGET (data);
+  _gtk_file_system_model_add_and_query_files (impl->priv->search_model,
+                                              files,
+                                              MODEL_ATTRIBUTES);
 
-  for (l = hits; l; l = l->next)
-    search_add_hit (impl, (gchar*)l->data);
+  g_list_free_full (files, g_object_unref);
 }
 
 /* Callback used from GtkSearchEngine when the query is done running */